<div [@routerTransition]>

    <div class="content d-flex flex-column flex-column-fluid">

        <sub-header [title]="'programList' | localize" [description]="'programList' | localize">
            <div action="back"><i class="icon-fanhui text-info" (click)="goBack()"></i></div>
            <div role="actions">
                <button class="btn btn-primary" (click)="goPublish()">
                    <i class="fa icon-fabu"></i>
                    {{l("publishSchedule")}}</button>
                <button class="btn btn-primary" (click)="createProgram()">
                    <i class="fa fa-plus"></i>
                    {{l("Create")}}{{l("programList")}}</button>
            </div>
        </sub-header>


        <div [class]="containerClass">
            <div class="card card-custom gutter-b">
                <div class="card-body">
                    <div class="row">
                        <form class="horizontal-form" autocomplete="off">
                            <div class="m-form m-form--label-align-right">
                                <div class="row align-items-center m--margin-bottom-10">
                                    <div class="col-4">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>{{l('name')}}</label>
                                            <div class="input-group">
                                                <input (keyup.enter)="getProgram()" [(ngModel)]="filterText"
                                                    name="filterText" autoFocus class="form-control m-input"
                                                    [placeholder]="l('SearchWithThreeDot')" type="text">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-2">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>&nbsp;</label>
                                            <div class="input-group">
                                                <button type="button" class="btn btn-primary"
                                                    [buttonBusy]="primengTableHelper.isLoading" (click)="getProgram()">
                                                    <i class="la la-refresh"></i>
                                                    {{l("search")}}
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="row align-items-center">
                        <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                            <p-table #dataTable (onLazyLoad)="getProgram($event)" [value]="primengTableHelper.records"
                                [rows]="primengTableHelper.defaultRecordsCountPerPage"
                                [(selection)]="programPublishList" [paginator]="false" [lazy]="true"
                                [resizableColumns]="primengTableHelper.resizableColumns"
                                [responsive]="primengTableHelper.isResponsive">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th>{{l('Actions')}}</th>
                                        <th style="width: 5.0em">
                                            <p-tableHeaderCheckbox></p-tableHeaderCheckbox>
                                        </th>
                                        <th style="width:5%">{{l('RecordId')}}</th>
                                        <th>{{l('name')}}</th>
                                        <th>{{l('PlayModel')}}</th>
                                        <th>{{l('executeMode')}}</th>
                                        <th>
                                            {{l('startTime')}}
                                        </th>
                                        <th>
                                            {{l('endTime')}}
                                        </th>
                                        <th>{{l('priority')}}</th>
                                        <!-- <th style="width:25%;">{{l('description')}}</th> -->
                                        <th pSortableColumn="effectiveTime">{{l('PublishTime')}}
                                            <p-sortIcon field="effectiveTime"></p-sortIcon>
                                        </th>
                                        <th pSortableColumn="updateTime">{{l('UpdateTime')}}
                                            <p-sortIcon field="updateTime"></p-sortIcon>
                                        </th>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="body" let-record let-i="rowIndex">
                                    <tr [pSelectableRow]="record" [attr.trid]="record.id">
                                        <td>
                                            <div class="btn-group dropdown" dropdown normalizePosition>
                                                <button class="dropdown-toggle btn btn-sm btn-primary"
                                                    data-toggle="dropdown" dropdownToggle aria-haspopup="true"
                                                    aria-expanded="false">
                                                    <i class="fa fa-cog"></i>
                                                    <span class="caret"></span> {{l("Actions")}}
                                                </button>
                                                <ul class="dropdown-menu" *dropdownMenu>
                                                    <li>
                                                        <a (click)="editProgram(record)"
                                                            class="icon-bianji dropdown-item">{{l('Edit')}}</a>
                                                    </li>
                                                    <li>
                                                        <a (click)="deleteProgram(record.id)"
                                                            class="icon-icon-test dropdown-item">{{l('Delete')}}</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <td>
                                            <p-tableCheckbox [value]="record"></p-tableCheckbox>
                                        </td>
                                        <td> {{transIndex(i)}}</td>
                                        <td>
                                            <span>{{record.name}}</span>
                                        </td>
                                        <td>
                                            <span *ngIf="record.content.playModel==0">{{l("Play in time")}}</span>
                                            <span *ngIf="record.content.playModel==1">{{l("Play in sequence")}}</span>
                                        </td>
                                        <td>
                                            <span *ngIf="record.content.model==0">{{l('section')}}</span>
                                            <span *ngIf="record.content.model==1">{{l('eachDay')}}</span>
                                            <span *ngIf="record.content.model==2">{{l('eachWeek')}}</span>
                                            <span *ngIf="record.content.model==3">{{l('eachMonth')}}</span>
                                        </td>
                                        <td>
                                            <span>{{record.startTime}}</span>
                                        </td>
                                        <td>
                                            <span>{{record.endTime}}</span>
                                        </td>
                                        <th><span>{{record.priority}}</span></th>
                                        <!-- <td>
                                                <span>{{record.extensionData}}</span>
                                            </td> -->
                                        <td>{{record.effectiveTime| date : "yyyy/MM/dd"}}</td>
                                        <td>{{record.lastModificationTime| date : "yyyy/MM/dd"}}</td>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="emptymessage" let-records>
                                    <tr *ngIf="primengTableHelper.records">
                                        <td colspan="8">
                                            <img class="emptymessage"
                                                src="/assets/common/images/placeholder/productHolder.png" />
                                        </td>
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-paging-container">
                                <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage" #paginator
                                    (onPageChange)="getProgram($event)"
                                    [totalRecords]="primengTableHelper.totalRecordsCount"
                                    [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">
                                </p-paginator>
                                <span class="total-records-count">
                                    {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                                </span>
                            </div>
                        </div>
                        <!--<Primeng-Datatable-End>-->
                    </div>







                    <div [ngClass]="{'hide':!toPublish,'float_panel':true,'beautyScroll':true}"
                        [ngStyle]="{'height':avalibleHeight}" *ngIf="toPublish">
                        <div class="panel_head">
                            <h3>{{l('publishSchedule')}}</h3>
                            <div class="text-right x">
                                <button (click)="toPublish=!toPublish">
                                    <i class="icon-close"></i>
                                </button>
                            </div>
                        </div>
                        <div class="panel_body">
                            <form (ngSubmit)="doPublishSchedule()" name="publishConForm">
                                <div class="form-group">
                                    <div class="radio-inline">
                                        <label class="radio">
                                            <input type="radio" name="publishType" [(ngModel)]="publishType"
                                                value="add">
                                            {{l('append')}}
                                            <span></span>
                                        </label>
                                        <label class="radio">
                                            <input type="radio" name="publishType" [(ngModel)]="publishType"
                                                value="update">
                                            {{l('update')}}
                                            <span></span>
                                        </label>
                                        <!-- <label class="kt-radio">
                                            <input type="radio" name="publishType" [(ngModel)]="publishType"
                                                value="delete">
                                            {{l('withdraw')}}
                                            <span></span>
                                        </label> -->
                                        <!-- <label class="kt-checkbox kt-checkbox--primary">
                                            <input class="form-control" [(ngModel)]="informDevice" type="checkbox"
                                                name="informDevice" />{{l("informDevice")}}
                                            <span></span>
                                        </label> -->
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="input-group">
                                        <input [(ngModel)]="treeFilter" name="treeFilterText" autoFocus
                                            class="form-control m-input" (keydown.enter)="filterTree($event)"
                                            [placeholder]="l('SearchWithThreeDot')" type="text">
                                        <span class="input-group-btn">
                                            <button class="btn btn-primary" type="button" (click)="filterTree()">
                                                <i class="icon-sousuo-sousuo"></i>
                                            </button>
                                        </span>
                                    </div>
                                </div>

                                <div class="form-group beautyScroll"
                                    [ngStyle]="{'max-height':'calc('+avalibleHeight+' - 253px)','padding-left':'20px'}">
                                    <app-my-tree #myTree [config]="{'showId':true,'name':'name','singleSelect':true}"
                                        [(items)]="scheduleTree">
                                    </app-my-tree>
                                    <h3 *ngIf="!scheduleTree||scheduleTree.length==0">{{l('NoData')}}</h3>
                                </div>

                                <div class="form-group text-right">
                                    <button *ngIf="scheduleTree&&scheduleTree.length" type="submit"
                                        class="btn btn-primary">{{l('Publish')}}</button>
                                </div>
                            </form>
                        </div>
                    </div>




                </div>
            </div>
        </div>

        <programModal #programModal (modalSave)="getProgram()"></programModal>

    </div>
</div>